#!/bin/bash

if [ ! -d "$1" ]; then
mkdir --mode=0777 -p "$1" || { echo "FATAL ERROR: temp dir creation failed"; exit; }
fi

echo "$$" > "$1/pid";


i=1;
t=$(($#-1));



for file in "${@:2}"; do

echo "0: $i/$t remove: $file" >> "$1/log";
rm -rf "$file" && echo "0: OK" >> "$1/log" || echo "0: FAILED" >> "$1/log"


let i++
done

echo "1: Done" >> "$1/log"

sleep 20

rm -rf "$1"
